/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static java.lang.Thread.sleep;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Timer;

/**
 *
 * @author Evistix
 */
public class SD extends javax.swing.JDialog {

    /**
     * Creates new form SD
     */
    int JD;
    public SD(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setIconImage(java.awt.Toolkit.getDefaultToolkit().createImage((getClass().getResource("/icon/nailuo.jpg"))));
        a.setVisible(false);
        a1.setVisible(false);
        a.setMinimum(0);
       a.setMaximum(100);
        a.setValue(0);
       a.setStringPainted(true);
        JD=0;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        a = new javax.swing.JProgressBar();
        a1 = new javax.swing.JLabel();
        扫描 = new javax.swing.JButton();
        暂停 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("杀毒");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/background/杀毒背景red.png"))); // NOI18N
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, -1, -1));

        a.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                aStateChanged(evt);
            }
        });
        a.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                aMouseClicked(evt);
            }
        });
        getContentPane().add(a, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 90, 560, 20));

        a1.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        a1.setText("正在进行全盘扫描...");
        getContentPane().add(a1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 60, 220, 30));

        扫描.setText("开始全盘扫描");
        扫描.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                扫描ActionPerformed(evt);
            }
        });
        getContentPane().add(扫描, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 30, -1, -1));

        暂停.setText("暂停");
        暂停.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                暂停ActionPerformed(evt);
            }
        });
        getContentPane().add(暂停, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 30, 100, -1));

        jButton2.setText("返回");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 30, -1, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/background/bg1.png"))); // NOI18N
        jLabel1.setText("正在进行全盘扫描");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 680, 470));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
public void Timer(){
        
    };

    Timer timer=new Timer(50,new ActionListener(){
        public void actionPerformed(ActionEvent e) {
           int value=a.getValue();
           if(value<100){
               value++;
              a.setValue(value);
           }
           if(a.getValue()==100){
               timer.stop();
            javax.swing.JOptionPane.showMessageDialog(rootPane,"杀毒完成"); 
            a.setVisible(false);
            a1.setVisible(false);
            扫描.setVisible(true);
            
            a.setValue(0);
        }
        }
    });
    private void 扫描ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_扫描ActionPerformed
        // TODO add your handling code here:
        a.setVisible(true);
        a1.setVisible(true);
        扫描.setVisible(false);
        timer.start();
        //a.setIndeterminate(true);
//        new Thread() {
//            @Override
//            public void run(){
//                for(JD=0;JD<=100;JD+=10){
//                    a2.setText(JD+"%");
//                    try {
//                        sleep(1000);
//                    } catch (InterruptedException ex) {
//                        Logger.getLogger(SD.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//                }
//            };
//        }.run();
        
    }//GEN-LAST:event_扫描ActionPerformed

    private void aStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_aStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_aStateChanged

    private void aMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aMouseClicked
        // TODO add your handling code here:
        if(JD<100) {
            JD+=20;
            a.setValue(JD);
        }
        if(JD==100){
            javax.swing.JOptionPane.showMessageDialog(rootPane,"杀毒完成"); 
            a.setVisible(false);
            a1.setVisible(false);
            扫描.setVisible(true);
            JD=0;
            a.setValue(JD);
        }
    }//GEN-LAST:event_aMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        //new Index().setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void 暂停ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_暂停ActionPerformed
        // TODO add your handling code here:
        timer.stop();
    }//GEN-LAST:event_暂停ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SD dialog = new SD(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar a;
    private javax.swing.JLabel a1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton 扫描;
    private javax.swing.JButton 暂停;
    // End of variables declaration//GEN-END:variables
}
